<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			let stus = [] //表示所有学生信息的数组
			function init(){
				let xhr = new XMLHttpRequest()
				xhr.open("GET","stus.xml",false)
				xhr.send()
				
				let data = xhr.responseXML  //data表示XML对象，文档内容DOM对象
				stus = data.querySelectorAll("stu")
				//stus = data.getElementsByTagName("stu")
				
				document.getElementById("sno").value = stus[0].getAttribute("sno")
				document.getElementById("sname").value = stus[0].getAttribute("name")
			}
			let index = 0
			function next(){
				index++
				if(index>=stus.length){
					index = 0
				}
				document.getElementById("sno").value = stus[index].getAttribute("sno")
				document.getElementById("sname").value = stus[index].getAttribute("name")
			}
		</script>
	</head>
	<body onload="init()">
		学号：<input type="text" id="sno"/><br>
		姓名：<input type="text" id="sname"/>
		<button type="button" onclick="next()">下一个</button>
	</body>
</html>
